<?php
namespace app\index\controller;
use app\common\controller\Api;

class StatsUser extends Api
{

    /**
     * @var \app\index\model\StatsUser
     */
    protected $model = null;

    public $primarykey = 'date';

    public $relationSearchArr = ['user'];

    public $sum_field = ['trade_count', 'trade_valid_count', 'trade_invalid_count', 'trade_pay_price', 'trade_pub_share_pre_fee', 'trade_tb_service_charge', 'trade_tb_tax_charge', 'trade_jf_income', 'trade_channel_income', 'trade_user_income', 'trade_share_income', 'trade_settle_user_income', 'trade_settle_share_income', 'coupon_count', 'coupon_valid_count', 'coupon_invalid_count', 'coupon_error_count'/*, 'user_count', 'user_unsubscribe', 'user_day_active', 'user_week_active', 'user_month_active'*/];

    public $other_field = ['date', 'user_id'];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('StatsUser');
    }

    public function _condition($condition){
        $filer_arr = [];
        $op_arr = [];

        $condition['user_id'] = $this->request->param('user_id');
        $condition['start_date'] = $this->request->param('start_date');
        $condition['end_date'] = $this->request->param('end_date');
        $this->is_sum_total = intval($this->request->param('is_sum_total'));

        if($condition['user_id']){
            $filer_arr['user_id'] = $condition['user_id'];
        }
        if($condition['start_date'] || $condition['end_date']){
            $filer_arr['date'] = $condition['start_date'].','.$condition['end_date'];
            $op_arr['date'] = 'BETWEEN'; 
        }
        return array($filer_arr, $op_arr);
    }
}
